package com.feizhi.inventory.fragment.exportdetails;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.feizhi.inventory.bean.InventoryDetailsBean;
import com.feizhi.inventory.databinding.ItemInventoryDetailsBinding;

import java.util.List;

/**
 *  数据导出适配器
 * */
public class ExportDetailsAdapter extends RecyclerView.Adapter<ExportDetailsAdapter.InventoryDetailsViewHolder> {

    private List<InventoryDetailsBean> data;
    private OnClickListener onClickListener;

    public ExportDetailsAdapter(List<InventoryDetailsBean> data) {
        this.data = data;
    }

    @Override
    public InventoryDetailsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemInventoryDetailsBinding mBinding = ItemInventoryDetailsBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new InventoryDetailsViewHolder(mBinding);
    }

    @Override
    public void onBindViewHolder(InventoryDetailsViewHolder holder, int position) {
        holder.mBinding.name.setText(data.get(position).getName());
        holder.mBinding.date.setText(data.get(position).getDate());
        holder.mBinding.number.setText(data.get(position).getNumber());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickListener.ItemOnClickListener(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data == null? 0 : data.size();
    }

    public class InventoryDetailsViewHolder extends RecyclerView.ViewHolder {

        private ItemInventoryDetailsBinding mBinding;

        public InventoryDetailsViewHolder(ItemInventoryDetailsBinding mBinding) {
            super(mBinding.getRoot());
            this.mBinding = mBinding;
        }
    }

    public void setItemOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        void ItemOnClickListener(int position);
    }
}
